/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nanosn.coffeemaker.server.restlet;

import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.restlet.Application;
import org.restlet.Context;
import org.restlet.ext.servlet.ServerServlet;

/**
 *
 * @author selkhateeb
 */
public class CoffeeMakerRestletServlet extends ServerServlet {

    @Override
    protected Application createApplication(Context parentContext) {

        System.out.println("Init Param[ProjectName]:" + getInitParameter(
                "ProjectName", null));

        //We need somehow to pass the RealPath for template loading
        //TODO: See if its possible to get it without this hack

        Application app = new CoffeeMakerApplication(this.getClass().getClassLoader());
        Logger.getLogger(CoffeeMakerRestletServlet.class.getName()).log(Level.INFO, "Well loggin is working!!");
        //Application app = super.createApplication(parentContext);

        if (app.getContext() == null) {
            app.setContext(new Context());
        }

        if (app.getContext().getAttributes() == null) {
            app.getContext().setAttributes(new HashMap<String, Object>());
        }
        app.getContext().getAttributes().put("RealPath",
                                             getServletContext().getRealPath(""));
        app.getContext().getAttributes().put("ProjectName",
                                             getInitParameter("ProjectName",
                                                              null));
        return app;
    }
}
